#include <iostream>
#include <algorithm>
#include <cstring>
#include <stdlib.h>
#include <stack>
using namespace std;
const int maxsize = 1000;
char buff[maxsize];
char expr[maxsize];
stack<char> st;
int priority(char ch)
{
    switch (ch)
    {
    case '+':
        return 1;
        break;
    case '-':
        return 1;
        break;
    case '*':
        return 2;
        break;
    case '/':
        return 2;
        break;
    case '(':
        return -3;
        break;
    case ')':
        return -4;
        break;
    default:
        return 0;
        break;
    }
}
void func()
{
    int len = strlen(buff), i, j;
    for (i = 0, j = 0; i < len; ++i)
    {
        if (priority(buff[i]) == 0)
            expr[j++] = buff[i];
        else
        {
            if (buff[i] == '(')
                st.push(buff[i]);
            else if (buff[i] == ')')
            {
                while (st.top() != '(')
                {
                    expr[j++] = st.top();
                    st.pop();
                }
                st.pop();
            }
            else
            {
                int pnow, ptop;
                pnow = priority(buff[i]);
                if (!st.empty())
                    do
                    {
                        ptop = priority(st.top());
                        if (ptop > 0)
                        {
                            expr[j++] = st.top();
                            st.pop();
                        }
                    } while (!st.empty() && pnow < ptop && ptop > 0);
                st.push(buff[i]);
            }
        }
    }
    while (!st.empty())
    {
        expr[j++] = st.top();
        st.pop();
    }
}
int main()
{
    cout << "Please input your expression!: ";
    cin >> buff;
    func();
    cout << "The expression can be express as: " << expr << endl;
    return 0;
}